;
//封装对象
function paginator(obj){
	var doc=document;
	
	/*初始化参数*/
	//当前页面，默认第一页
	this.currentPage=obj.currentPage || 1;
	//总页面
	this.maxPage=parseInt(obj.maxPage);
	//获取DOM节点
	this.readonly=doc.querySelector(obj.readonly);
	this.firstPage=doc.querySelector(obj.firstPage);
	this.lastPage=doc.querySelector(obj.lastPage);
	this.nextPage=doc.querySelector(obj.nextPage);
    this.prevPage=doc.querySelector(obj.prevPage);
    this.jumpTo=doc.querySelector(obj.goPage);
    //点击函数
    this.fn=obj.callback;
    
    //执行
    this.init();
};

//封装主要方法
paginator.prototype={
	
	//下一页
	goNext:function(){
		var that=this;
		this.nextPage.onclick=function(){
			if(that.currentPage<that.maxPage){
				that.currentPage++;
				that.callback();
			}
		};
	},
	
	//上一页
	goPrev:function(){
		var that=this;
		this.prevPage.onclick=function(){
			if(that.currentPage>1 && that.currentPage<=that.maxPage){
				that.currentPage--;
				that.callback();
			}
		};
	},
	
	//跳转到指定页面
	goPage:function(){
		var that=this;
		this.jumpTo.onclick=function(){
			
			var value=parseInt(that.readonly.value);
			//console.log(value);

			if (value!=null && value!="" && value>=1){
				
			    if(value<=that.maxPage){
			    	that.currentPage=value;
			    }
			    
			    if(value>that.maxPage){
			    	that.currentPage=that.maxPage;
			    }
			    
			}else{
				that.currentPage=1;
			}
			
			that.callback();
		}	
	},
	
	//跳转到首页
	goFirst:function(){
		var that=this;
		this.firstPage.onclick=function(){
			that.currentPage=1;
			that.callback();
		}
	},
	
	//跳转到末页
	goLast:function(){
		var that=this;
		this.lastPage.onclick=function(){
			that.currentPage=that.maxPage;
			that.callback();
		}
	},
	
	//回调函数
    callback:function(){
    	//console.log(this.currentPage);
    	this.readonly.value=this.currentPage+"/"+this.maxPage;
    	this.fn();
    },
	
	//执行初始化函数
	init:function(){
		this.callback();
		this.goFirst();
		this.goLast();
		this.goNext();
		this.goPrev();
		this.goPage();
	}
};